﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.IO;
using WindowsFormsApplication9;

namespace TestProject2
{


    [TestClass()]
    public class DS_net_Client_Test
    {
        string FilePath = @"8060.port";

        [TestMethod()]
        public void net_CreateAndReadTest()
        {
            // Create() and Read() 

            DS_Net_Client target = new DS_Net_Client();
            target.IsReady(FilePath);
            target.Clear();

            Person _newPerson = new Person();
            _newPerson.FName = "Bob"; _newPerson.Age = 54; _newPerson.LName = "Harris";
            Person _newPerson2 = new Person();
            _newPerson2.FName = "Mina"; _newPerson2.Age = 35; _newPerson2.LName = "Harris";

            target.Create(_newPerson);
            target.Create(_newPerson2);

            // if not throws - means "success" to Create, and:
            List<Person> list = target.Read();
            Assert.AreEqual(2, list.Count);
        }

        [TestMethod()]
        public void net_DeleteTest()
        {
            DS_Net_Client target = new DS_Net_Client();
            target.IsReady(FilePath);
            target.Clear();

            Person _newPerson = new Person();
            _newPerson.FName = "Bob"; _newPerson.Age = 54; _newPerson.LName = "Harris";
            Person _newPerson2 = new Person();
            _newPerson2.FName = "Mina"; _newPerson2.Age = 35; _newPerson2.LName = "Harris";

            target.Create(_newPerson);
            target.Create(_newPerson2);
            target.Delete(0);

            List<Person> list = target.Read();
            Assert.AreEqual(1, list.Count);
            Assert.AreEqual("Mina;Harris;35", list[0].ReturnLineToCsv());
        }

        [TestMethod()]
        public void net_GetFilterTest()
        {
            DS_Net_Client target = new DS_Net_Client();
            string expected = "TcpClient (*.port)|*.port";
            string actual;
            actual = target.GetFilter();
            Assert.AreEqual(expected, actual);
        }


        [TestMethod()]
        public void net_UpdateTest()
        {
            DS_Net_Client target = new DS_Net_Client();
            target.IsReady(FilePath);
            target.Clear();

            Person _newPerson = new Person();
            _newPerson.FName = "Bob"; _newPerson.Age = 54; _newPerson.LName = "Harris";
            Person _newPerson2 = new Person();
            _newPerson2.FName = "Mina"; _newPerson2.Age = 35; _newPerson2.LName = "Harris";

            target.Create(_newPerson);
            target.Create(_newPerson2);

            target.Update(0, _newPerson2); // Bob -> Mina

            // if not throws - means "success", but:
            List<Person> list = target.Read();
            Assert.AreEqual(2, list.Count);
            Assert.AreEqual("Mina;Harris;35", list[0].ReturnLineToCsv());
        }
    }
}
